﻿using System;
using System.Collections.Generic;

using System.Text;

namespace Estimate.Common.DBFieldTypes
{
    /// <summary>
    /// 预报的时效
    /// </summary>
    [Serializable]
    public enum ForeSpanType 
    {
        FD00_12, //未来0_12小时
        FD12_24, //未来12_24小时
        FD00_24, //未来0_24小时
        FD24_36, //未来24_36小时
		FD36_48, //未来36_48小时
        FD24_48, //未来24_48小时
		FD48_60, //未来48_60小时
		FD60_72, //未来60_72小时
        FD48_72, //未来48_72小时
		FD72_84, //未来72_84小时
		FD84_96, //未来84_96小时
        FD72_96, //未来72_96小时
		FD96_108, //未来24_36小时
		FD108_120, //未来108_120小时
        FD96_120, //未来96_120小时
        FD120_132, //未来120-132小时
        FD132_144, //未来132-144小时
        FD120_144, //未来120-144小时
        FD144_156, //未来144-156小时
        FD156_168, //未来156-168小时
        FD144_168, //未来144-168小时

    }

    public static class ForeSpanTypeTools
    {
        public static void Get12Spans(ForeSpanType span, out ForeSpanType fore12Span, out ForeSpanType last12Span)
        {
            

            //针对span初始化 PastDay, Is24Hours, IsFirst12
            string strSpan = span.ToString().Replace("FD", "");
            string[] hours = strSpan.Split('_');
            int start = Convert.ToInt32(hours[0]);
            int end = Convert.ToInt32(hours[1]);


            if ((end - start) != 24)
            {
                throw new Exception("不能转换，需要该span是24时的");
            }
            else
            {
                int middle = (start + end )/2;
                
                string strStart = start.ToString();
                if( start == 0)
                    strStart = "00";
                fore12Span = (ForeSpanType)Enum.Parse(typeof(ForeSpanType), string.Format("FD{0}_{1}",strStart,middle.ToString()));
                last12Span = (ForeSpanType)Enum.Parse(typeof(ForeSpanType), string.Format("FD{0}_{1}",middle.ToString(), end.ToString()));
            }


        }

        public static bool Is24HourSpan(ForeSpanType span)
        {
            string strSpan = span.ToString().Replace("FD", "");
            string[] hours = strSpan.Split('_');
            int start = Convert.ToInt32(hours[0]);
            int end = Convert.ToInt32(hours[1]);


            return (end - start) == 24;
        }
    }
}
